package org.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.example.controller"))
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }

    @Bean
    public Docket adminApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("admin") // 分组名称
                .select()
                .apis(RequestHandlerSelectors.basePackage("org.example.controller.admin")) // 指定分组的控制器包路径
                .paths(PathSelectors.any())
                .build()
                .apiInfo(adminApiInfo());
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("公共API文档")
                .description("这是公共API的文档，适用于所有用户")
                .version("1.0")
                .contact(new Contact("Kimi", "https://example.com", "kimi@example.com"))
                .build();
    }

    private ApiInfo adminApiInfo() {
        return new ApiInfoBuilder()
                .title("管理员API文档")
                .description("这是管理员专用的API文档")
                .version("1.0")
                .contact(new Contact("Admin", "https://admin.example.com", "admin@example.com"))
                .build();
    }
}

